{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Mayavi tvtk\n",
    "===========\n",
    "\n",
    "||\\<\\#80FF80\\> This page is not the main source of documentation. You\n",
    "are invited to refer to the [Mayavi2 home\n",
    "page](http://enthought.github.com/mayavi/mayavi) for up-to-date\n",
    "documentation on TVTK. In particular, bear in mind that if you are\n",
    "looking for a high-level Python 3D plotting library, Mayavi also\n",
    "provides the right API, and can be embedded (see the [user\n",
    "guide](http://enthought.github.com/mayavi/mayavi/building_applications.html)).\n",
    "||"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What is tvtk?\n",
    "=============\n",
    "\n",
    "``tvtk`` is a `traits <http://www.enthought.com/traits>`_ \n",
    "enabled version of `VTK <http://www.vtk.org>`_\n",
    "for 3D graphics and visualization.\n",
    "\n",
    "It provides an exact match to the VTK objects, but with a Pythonic feel, unlike `Mayavi <http://code.enthought.com/projects/mayavi>`_ which aims to provide new APIs\n",
    "\n",
    "Most important features are\n",
    "\n",
    "* All VTK classes are wrapped.\n",
    "* Support for traits.\n",
    "* Elementary pickle support.\n",
    "* Pythonic feel.\n",
    "* Handles numpy/Numeric/numarray arrays/Python lists transparently.\n",
    "* Support for a pipeline browser, `ivtk` \n",
    "* High-level `mlab` module.\n",
    "* Envisage plugins for a tvtk scene and the pipeline browser.\n",
    "* MayaVi2 is built on top of tvtk\n",
    "\n",
    "See the `enthought TVTK page <http://www.enthought.com/enthought/wiki/TVTK>`_ for more details,\n",
    "in particular the `tvtk introduction <http://www.enthought.com/enthought/wiki/TVTKIntroduction>`_.\n",
    "\n",
    "tvtk examples\n",
    "-------------\n",
    "\n",
    "cone\n",
    "````\n",
    "\n",
    "The following example displays a cone which can be rotated/scaled/... with the mouse.\n",
    "[Simple_tvtk_cone.py](files/attachments/MayaVi_tvtk/Simple_tvtk_cone.py)\n",
    "\n",
    "quadrics\n",
    "````````\n",
    "\n",
    "A more interesting example is the generation of some contour surfaces of an implicit function.\n",
    "#[Vis_quad.py](files/attachments/MayaVi_tvtk/Vis_quad.py)\n",
    "\n",
    "This displays the following scene on screen and also saves it to a file.\n",
    "\n",
    "![](files/attachments/MayaVi_tvtk/vis_quad.png)\n",
    "\n",
    "\n",
    "ivtk\n",
    "----\n",
    "\n",
    "The module `tools.ivtk` makes VTK/TVTK easier to use from the Python\n",
    "interpreter. \n",
    "For example, start IPython with::\n",
    "\n",
    "  ipython -wthread \n",
    "\n",
    "(if you have both wxPython 2.4 and wxPython 2.6 installed you will need a recent IPython\n",
    "and do ``ipython -wthread  -wxversion 2.6``)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then you can paste the following lines:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "  from enthought.tvtk.tools import ivtk\n",
    "  from enthought.tvtk.api import tvtk\n",
    "  # Create a cone:\n",
    "  cs = tvtk.ConeSource(resolution=100)\n",
    "  mapper = tvtk.PolyDataMapper(input=cs.output)\n",
    "  actor = tvtk.Actor(mapper=mapper)\n",
    "\n",
    "  # Now create the viewer:\n",
    "  v = ivtk.IVTKWithCrustAndBrowser(size=(600,600))\n",
    "  v.open()\n",
    "  v.scene.add_actors(actor)  # or v.scene.add_actor(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can then explore the visualization pipeline and modify any settings.\n",
    "\n",
    "![](files/attachments/MayaVi_tvtk/ivtk_example.png)\n",
    ")\n",
    "\n",
    "For creating the viewer there are different options:\n",
    "\n",
    "- ``v = ivtk.viewer()`` - this one does not need the ``v.open()`` and the ``size=(600,600)``\n",
    "- ``v = ivtk.IVTK()``\n",
    "- ``v = ivtk.IVTKWithCrust()``\n",
    "- ``v = ivtk.IVTKWithBrowser()``\n",
    "- ``v = ivtk.IVTKWithCrustAndBrowser)``\n",
    "\n",
    "For viewers with `Crust` you can use the python command line window to modify the pipeline."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
